package org.hsqldb.index;

import org.hsqldb.Row;
import org.hsqldb.RowAVLDisk;
import org.hsqldb.RowLinkList;
import org.hsqldb.lib.IntLookup;
import org.hsqldb.persist.CachedObject;
import org.hsqldb.persist.PersistentStore;
import org.hsqldb.rowio.RowInputInterface;
import org.hsqldb.rowio.RowOutputInterface;

public class NodeLinkList implements CachedObject {

	
	static final int NO_POS = RowAVLDisk.NO_POS;

	public static int SIZE_IN_BYTE = 4 * 4;

    public NodeLinkList nodeNextIndex;// node of next index (nNext==null || nNext.iId=iId+1)

	protected NodeLinkList nPre;
	protected NodeLinkList nNext;
    //protected NodeLinkList nParent;
    protected final Row row;

    NodeLinkList() {
        row = null;
    }

    public NodeLinkList(Row r) {
        row = r;
    }

    public NodeLinkList(RowLinkList rowLinkList, RowInputInterface in, int i) {
		// TODO Auto-generated constructor stub
    	//FIXME: This is used to read a index node from file
    	row = rowLinkList;
	}

	public void delete() {
        //iBalance = 0;
        nPre    = nNext = null;
    }

    NodeLinkList getPre(PersistentStore store) {
        return nPre;
    }

    NodeLinkList setPre(PersistentStore persistentStore, NodeLinkList n) {
        nPre = n;
        return this;
    }

    boolean isPre(NodeLinkList node) {
        return nPre == node;
    }
    boolean isNext(NodeLinkList node) {
        return nNext == node;
    }

    NodeLinkList getNext(PersistentStore persistentStore) {
        return nNext;
    }

    NodeLinkList setNext(PersistentStore persistentStore, NodeLinkList n) {

        nNext = n;
        return this;
    }

    public NodeLinkList set(PersistentStore store, boolean isPre, NodeLinkList n) {

        if (isPre) {
            nPre = n;
            if(n != null) n.nNext = this;
        } else {
            nNext = n;
            if(n != null) n.nPre = this;
        }

        return this;
    }


    boolean equals(NodeLinkList n) {
        return n == this;
    }

    public void setInMemory(boolean in) {}

    public void write(RowOutputInterface out) {
    	System.out.println("Writing");
    }

    public void write(RowOutputInterface out, IntLookup lookup) {
    	System.out.println("Writing");
    }

    public int getPos() {
        return 0;
    }

    protected Row getRow(PersistentStore store) {
        return row;
    }

    protected Object[] getData(PersistentStore store) {
        return row.getData();
    }


    public void updateAccessCount(int count) {}

    public int getAccessCount() {
        return 0;
    }

    public void setStorageSize(int size) {}

    public int getStorageSize() {
        return 0;
    }

    public void setPos(int pos) {}

    public boolean hasChanged() {
        return false;
    }

    public boolean isKeepInMemory() {
        return false;
    }
    ;

    public boolean keepInMemory(boolean keep) {
        return true;
    }

    public boolean isInMemory() {
        return row.isInMemory();
    }

    public void restore() {}

    public void destroy() {}

    public int getRealSize(RowOutputInterface out) {
        return 0;
    }

    public boolean isMemory() {
        return true;
    }
}
